import { FormProps, FormSchema } from '@/components/Table'
import { BasicColumn } from '@/components/Table/src/types/table'
import { pattern } from '@/utils/validate/index'

// 租户列表
export function getTenantBasicColumns(): BasicColumn[] {
  return [
    {
      title: '姓名',
      width: 120,
      dataIndex: 'userName'
    },
    {
      title: '手机号码',
      dataIndex: 'phoneNumber'
    },
    {
      title: '联系邮箱',
      dataIndex: 'email'
    },
    {
      title: '所属租户',
      dataIndex: 'topOrgName'
    },
    {
      title: '剩余时间',
      width: 120,
      dataIndex: 'authRemainingDays',
      align: 'right'
    },
    {
      title: '账号状态',
      width: 120,
      dataIndex: 'userStatus'
    },
    {
      title: '操作',
      width: 144,
      dataIndex: 'operate'
    }
  ]
}

export function getSearchFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 80,
    baseColProps: {
      span: 8,
      md: 12,
      xl: 8,
      xxl: 8
    },
    schemas: [
      {
        field: 'userName',
        label: '姓名',
        component: 'Input'
      },
      {
        field: 'phoneNumber',
        label: '手机号码',
        component: 'Input'
      },
      {
        field: 'email',
        label: '联系邮箱',
        component: 'Input'
      }
    ]
  }
}

// 租户信息表单
export function getTenantFormConfig(): Partial<FormProps> {
  return {
    showActionButtonGroup: false,
    layout: 'vertical',
    rowProps: {
      gutter: 64
    },
    baseColProps: {
      span: 12,
      style: {
        marginBottom: '4px'
      }
    },
    schemas: [
      {
        field: 'orgStatus',
        component: 'Switch',
        label: '企业状态',
        colProps: {
          span: 24
        },
        defaultValue: '0',
        componentProps: {
          checkedChildren: '启用',
          unCheckedChildren: '停用',
          checkedValue: '0',
          unCheckedValue: '1'
        }
      },
      {
        field: 'orgName',
        component: 'Input',
        label: '企业名称',
        required: true
      },
      {
        field: 'textHide',
        component: 'BasicTxt',
        label: '',
        componentProps: {
          textHide: true
        }
      },
      {
        field: 'taxesNumber',
        component: 'Input',
        label: '主机构税号',
        componentProps: {
          maxLength: 40
        },
        rules: [
          {
            required: true,
            validator: async (rule, value) => {
              if (!value) {
                return Promise.reject('请输入主机构税号')
              } else if (!pattern.regexp_tax.test(value)) {
                return Promise.reject('税号由大写英文和数字组成')
              } else {
                return Promise.resolve()
              }
            }
          }
        ]
      },
      {
        field: 'taxesType',
        component: 'Select',
        label: '纳税人类型',
        rules: [{ required: true, trigger: 'change' }],
        componentProps: {
          options: [
            {
              label: '小规模纳税人',
              value: '0',
              key: '0'
            },
            {
              label: '一般纳税人',
              value: '1',
              key: '1'
            }
          ]
        }
      },
      {
        field: 'gaap',
        component: 'Select',
        label: '会计准则',
        rules: [{ required: true, trigger: 'change' }],
        componentProps: {
          fieldNames: { label: 'itemName', value: 'itemCode' },
          options: []
        }
      },
      {
        field: 'industry',
        component: 'Select',
        label: '所属行业',
        componentProps: {
          fieldNames: { label: 'industryName', value: 'industryCode' },
          options: []
        }
      },
      {
        field: 'bankName',
        component: 'Input',
        label: '开户银行',
        required: true
      },
      {
        field: 'bankAccount',
        component: 'Input',
        label: '银行账号',
        required: true
      },
      {
        field: 'cellTel',
        component: 'Input',
        label: '注册电话',
        required: true
      },
      {
        field: 'address',
        component: 'Input',
        label: '注册地址',
        required: true
      },
      {
        field: 'contactPhone',
        component: 'Input',
        label: '联系人手机号',
        subLabel: {
          isShow: true,
          title: '超管账号密码将会发送至该手机号',
          style: {
            color: '#4AA353'
          }
        },
        // helpMessage: ['租户超级管理员账号密码将会以短信方式放送至该手机号'],
        rules: [
          {
            required: true,
            message: '请输入联系人手机号'
          },
          {
            pattern: pattern.regexp_cell_phone,
            message: '请输入正确的联系人手机号'
          }
        ]
      },
      {
        field: 'contactEmail',
        component: 'Input',
        label: '联系人邮箱',
        subLabel: {
          isShow: true,
          title: '进项产品必填',
          style: {
            color: '#C72A2A'
          }
        },
        rules: [
          {
            pattern: pattern.regexp_email,
            message: '请输入正确的联系人邮箱'
          }
        ]
      },
      {
        field: 'serviceType',
        component: 'Select',
        label: '服务类型',
        subLabel: {
          isShow: true,
          title: '销项产品必填',
          style: {
            color: '#C72A2A'
          }
        },
        componentProps: {
          fieldNames: { label: 'itemName', value: 'itemCode' },
          options: []
        }
      },
      {
        field: 'taxPlateType',
        component: 'Select',
        label: '税盘类型',
        subLabel: {
          isShow: true,
          title: '销项产品必填',
          style: {
            color: '#C72A2A'
          }
        },
        componentProps: {
          fieldNames: { label: 'itemName', value: 'itemCode' },
          options: []
        }
      },
      {
        field: 'aceId',
        component: 'Input',
        label: '采集鉴权ID',
        subLabel: {
          isShow: true,
          title: '进项产品必填',
          style: {
            color: '#C72A2A'
          }
        }
      },
      {
        field: 'aceKey',
        component: 'Input',
        label: '采集鉴权Key',
        subLabel: {
          isShow: true,
          title: '进项产品必填',
          style: {
            color: '#C72A2A'
          }
        }
      },
      {
        field: 'orgRemark',
        component: 'InputTextArea',
        label: '备注',
        componentProps: {
          autoSize: { minRows: 3, maxRows: 3 },
          maxLength: 30,
          placeholder: '请输入备注，中文30字以内'
        }
      }
    ]
  }
}
